package com.ruoyi.gradeUpdate.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gradeUpdate.domain.DistributionGradeUpdate;
import com.ruoyi.gradeUpdate.service.IDistributionGradeUpdateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分销等级升级条件Controller
 * 
 * @author ruoyi
 * @date 2025-10-11
 */
@RestController
@RequestMapping("/ruoyi/gradeUpdate")
public class DistributionGradeUpdateController extends BaseController
{
    @Autowired
    private IDistributionGradeUpdateService distributionGradeUpdateService;

    /**
     * 查询分销等级升级条件列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:gradeUpdate:list')")
    @GetMapping("/list")
    public TableDataInfo list(DistributionGradeUpdate distributionGradeUpdate)
    {
        startPage();
        List<DistributionGradeUpdate> list = distributionGradeUpdateService.selectDistributionGradeUpdateList(distributionGradeUpdate);
        return getDataTable(list);
    }

    /**
     * 导出分销等级升级条件列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:gradeUpdate:export')")
    @Log(title = "分销等级升级条件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DistributionGradeUpdate distributionGradeUpdate)
    {
        List<DistributionGradeUpdate> list = distributionGradeUpdateService.selectDistributionGradeUpdateList(distributionGradeUpdate);
        ExcelUtil<DistributionGradeUpdate> util = new ExcelUtil<DistributionGradeUpdate>(DistributionGradeUpdate.class);
        util.exportExcel(response, list, "分销等级升级条件数据");
    }

    /**
     * 获取分销等级升级条件详细信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:gradeUpdate:query')")
    @GetMapping(value = "/{updateId}")
    public AjaxResult getInfo(@PathVariable("updateId") Long updateId)
    {
        return success(distributionGradeUpdateService.selectDistributionGradeUpdateByUpdateId(updateId));
    }

    /**
     * 新增分销等级升级条件
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:gradeUpdate:add')")
    @Log(title = "分销等级升级条件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DistributionGradeUpdate distributionGradeUpdate)
    {
        return toAjax(distributionGradeUpdateService.insertDistributionGradeUpdate(distributionGradeUpdate));
    }

    /**
     * 修改分销等级升级条件
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:gradeUpdate:edit')")
    @Log(title = "分销等级升级条件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DistributionGradeUpdate distributionGradeUpdate)
    {
        return toAjax(distributionGradeUpdateService.updateDistributionGradeUpdate(distributionGradeUpdate));
    }

    /**
     * 删除分销等级升级条件
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:gradeUpdate:remove')")
    @Log(title = "分销等级升级条件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{updateIds}")
    public AjaxResult remove(@PathVariable Long[] updateIds)
    {
        return toAjax(distributionGradeUpdateService.deleteDistributionGradeUpdateByUpdateIds(updateIds));
    }
}
